<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="交通类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择交通类型"
          clearable
          class="!w-240px"
          @change="handleQuery"
        >
          <el-option key="0" label="飞机" value="0"/>
          <el-option key="1" label="铁路" value="1"/>
          <el-option key="2" label="汽车" value="2"/>
        </el-select>
      </el-form-item>

<!--      <el-form-item label="起点位置" prop="startLocation">-->
<!--        <el-input-->
<!--          v-model="queryParams.startLocation"-->
<!--          placeholder="请输入起点位置"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--          class="!w-150px"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="起点时间" prop="startTime">
        <el-date-picker
          v-model="queryParams.startTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-220px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<!--        <el-button @click="openForm('create')"><Icon icon="ep:plus" class="mr-5px" /> 新增</el-button>-->
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="交通类型" align="center" prop="type">
        <template #default="scope">
          <span v-if="scope.row.type === 0">飞机</span>
          <span v-if="scope.row.type === 1">铁路</span>
          <span v-if="scope.row.type === 2">汽车</span>
        </template>
      </el-table-column>
      <el-table-column label="起点位置" align="center" prop="startLocation" />
      <el-table-column label="终点位置" align="center" prop="endLocation" />
      <el-table-column
        label="开车时间"
        align="center"
        prop="busstarttime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column
        label="购票时间"
        align="center"
        prop="operationtime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="车次" align="center" prop="transportationNumber" />
      <el-table-column label="车牌号" align="center" prop="carno" />
      <el-table-column label="联系方式" align="center" prop="passengerPhone" />
<!--      <el-table-column label="操作" align="center" min-width="120px">-->
<!--        <template #default="scope">-->
<!--          <el-button-->
<!--            link-->
<!--            type="primary"-->
<!--            @click="openForm('update', scope.row.id)"-->
<!--            v-hasPermi="['member:transportation-record:update']"-->
<!--          >-->
<!--            编辑-->
<!--          </el-button>-->
<!--          <el-button-->
<!--            link-->
<!--            type="danger"-->
<!--            @click="handleDelete(scope.row.id)"-->
<!--            v-hasPermi="['member:transportation-record:delete']"-->
<!--          >-->
<!--            删除-->
<!--          </el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

</template>

<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import { TransportationRecordApi, TransportationRecordVO } from '@/api/member/transportationrecord'

/** 交通记录 列表 */
defineOptions({ name: 'Transportation' })

// const message = useMessage() // 消息弹窗
// const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<TransportationRecordVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数

const { personId } = defineProps({
  personId: {
    type: [String, Array], // 同时支持字符串和数组类型
    required: true
  }
})

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  createTime: [],
  personId: personId,
  ticketNumber: undefined,
  type: undefined,
  startLocation: undefined,
  endLocation: undefined,
  startTime: [],
  endTime: [],
  duration: undefined,
  transportationNumber: undefined,
  source: undefined,
  passengerName: undefined,
  passengerPhone: undefined,
  seatNumber: undefined,
  totalPrice: undefined,
  remark: undefined,
  readStatus: undefined,
  busstarttime: [],
  operationtime: [],
  carno: undefined,
  checkintime: []
})
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await TransportationRecordApi.getTransportationRecordPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}
//
// /** 添加/修改操作 */
// const formRef = ref()
// const openForm = (type: string, id?: number) => {
//   formRef.value.open(type, id)
// }
//
// /** 删除按钮操作 */
// const handleDelete = async (id: number) => {
//   try {
//     // 删除的二次确认
//     await message.delConfirm()
//     // 发起删除
//     await TransportationRecordApi.deleteTransportationRecord(id)
//     message.success(t('common.delSuccess'))
//     // 刷新列表
//     await getList()
//   } catch {}
// }

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
